package com.cbwl.eoas.cms.web.controller.eoas;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cbwl.eoas.cms.api.eoas.IAppMessageInfoService;
import com.cbwl.eoas.cms.api.sysconfig.IDictDetailService;
import com.cbwl.eoas.cms.model.eoas.AppMessageInfoDTO;
import com.cbwl.eoas.cms.model.sysconfig.DictDetailDTO;
import com.cbwl.eoas.common.framework.session.SessionManager;
import com.cbwl.eoas.common.framework.vo.PageRequest;
import com.cbwl.eoas.common.util.constain.DicTypeConstant;
import com.cbwl.eoas.common.web.Result;
import com.github.pagehelper.PageInfo;



/**
 * 
 * <p>[描述信息：注释]</p>
 *
 * @author 虞云波 - yuyunbo@3856.cc
 * @version 1.0 Created on 2017年10月12日 下午13:29:23
 */
@Controller
@RequestMapping("/appmessageinfo")
public class AppMessageInfoController {
	
	//业务层注解
	@Autowired
	private IAppMessageInfoService appMessageInfoService;
	
	
	//业务层注解
	@Autowired
	private IDictDetailService dictDetailService;

	
	private static Logger logger = LoggerFactory.getLogger(AppMessageInfoController.class);
	
	/**
	 * <p>初始化界面</p>
	 * 
	 * @return
	 * @author 虞云波 - yuyunbo@3856.cc
	 * @version 1.0 Created on 2017年10月12日 下午13:29:23
	 */
	@RequestMapping("/initAppMessageInfo")
	public String initAppMessageInfoPage() {
		return "initAppMessageInfo";
	}


	/**
	 * <p>初始化新增修改界面</p>
	 * 
	 * @return
	 * @author 虞云波 - yuyunbo@3856.cc
	 * @version 1.0 Created on 2017年10月12日 下午13:29:23
	 */
	@RequestMapping("/initAddUpdateAppMessageInfoPage")
	public String initAddUpdateAppMessageInfoPage(HttpServletRequest request,AppMessageInfoDTO bean) {
		
		request.setAttribute("bean", appMessageInfoService.getObjectById(bean));
		DictDetailDTO detailBean = new DictDetailDTO();
		detailBean.setDictTypeNo(DicTypeConstant.state);
		request.setAttribute("statusList", dictDetailService.queryObjectList(detailBean));
		
		detailBean.setDictTypeNo(DicTypeConstant.ami_type);
		request.setAttribute("beanList", dictDetailService.queryObjectList(detailBean));
		
		return "initAddUpdateAppMessageInfoPage";
	}
	

	/**
	 * <p>查询（分页）</p>
	 * 
	 * @param bean
	 * @return
	 * @author 虞云波 - yuyunbo@3856.cc
	 * @version 1.0 Created on 2017年10月12日 下午13:29:23
	 */
	@RequestMapping("/queryAppMessageInfoPage")
	@ResponseBody
	public Object queryAppMessageInfoPage(AppMessageInfoDTO bean,PageRequest pageRequest) {
		
		Result result = new Result(Result.Status.OK, "查询成功", "200");
		// 分页查询用户信息
		PageInfo<?> orgPageInfo =  appMessageInfoService.queryPageList(bean, pageRequest);
		result.setData(orgPageInfo);
		return result;
	}

	/**
	 * 
	 * <p>通过id查询主体信息</p>
	 * 
	 * @param bean
	 * @return
	 * @author 虞云波 - yuyunbo@3856.cc
	 * @version 1.0 Created on 2017年10月12日 下午13:29:23
	 */
	@RequestMapping("/getAppMessageInfoById")
	@ResponseBody
	public Object getAppMessageInfoById(AppMessageInfoDTO bean) {
		return appMessageInfoService.getObjectById(bean);
	}

	/**
	 * 
	 * <p>保存主体信息</p>
	 * 
	 * @param bean
	 * @return
	 * @author 虞云波 - yuyunbo@3856.cc
	 * @version 1.0 Created on 2017年10月12日 下午13:29:23
	 */
	@RequestMapping("/saveAppMessageInfo")
	@ResponseBody
	public Object saveAppMessageInfo(AppMessageInfoDTO bean) throws Exception {
		bean.setGmtCreate(new Date());
		bean.setCreater(SessionManager.getCurrentUser().getId());
		logger.info("{}保存消息信息",SessionManager.getCurrentUser().getEmpName());
		return appMessageInfoService.saveObject(bean);
	}

	/**
	 * 
	 * <p>更新主体信息</p>
	 * 
	 * @param bean
	 * @return
	 * @author 虞云波 - yuyunbo@3856.cc
	 * @version 1.0 Created on 2017年10月12日 下午13:29:23
	 */
	@RequestMapping("/updateAppMessageInfo")
	@ResponseBody
	public Object updateAppMessageInfo(AppMessageInfoDTO bean) throws Exception {		
		bean.setGmtModified(new Date());
		bean.setModifier(SessionManager.getCurrentUser().getId());
		logger.info("{}修改消息信息",SessionManager.getCurrentUser().getEmpName());
		return appMessageInfoService.updateObject(bean);
	}

	/**
	 * 
	 * <p>删除主体信息</p>
	 * 
	 * @param bean
	 * @return
	 * @author 虞云波 - yuyunbo@3856.cc 
	 * @version 1.0 Created on 2017年10月12日 下午13:29:23
	 * @throws Exception 
	 */
	@RequestMapping("/deleteAppMessageInfo")
	@ResponseBody
	public Object deleteAppMessageInfo(AppMessageInfoDTO bean) throws Exception {
		logger.info("{}删除消息信息",SessionManager.getCurrentUser().getEmpName());
		return appMessageInfoService.deleteObject(bean);
	}
}
